package com.tarena.lbs.controller;

import com.tarena.lbs.service.UserCouponsService;
import com.tarena.lbs.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/coupons")
@Tag(name = "用户优惠券接口")
@Api(value = "用户优惠券接口", tags = "用户优惠券接口")
public class UserCouponsController {
    @Autowired
    private UserCouponsService userCouponsService;

    @Autowired
    private JwtUtil jwtUtil;

    @DeleteMapping("/{id}")
    @Operation(summary = "删除用户优惠券")
    @ApiOperation(value = "删除用户优惠券", notes = "根据优惠券ID和用户ID删除用户持有的优惠券")
    public boolean deleteUserCoupon(
            @ApiParam(value = "优惠券ID", required = true, name = "id", example = "1")
            @PathVariable Integer id,
            @ApiParam(value = "用户ID", required = true, name = "userId", example = "1")
            @RequestParam Integer userId
    ) {
        return userCouponsService.deleteUserCoupon(id, userId);
    }

    @DeleteMapping("/batch")
    @Operation(summary = "批量删除用户优惠券")
    @ApiOperation(value = "批量删除用户优惠券", notes = "根据优惠券ID列表和用户ID批量删除用户持有的优惠券")
    public boolean batchDeleteUserCoupons(
            @ApiParam(value = "优惠券ID列表", required = true, name = "ids", example = "1,2,3")
            @RequestParam List<Integer> ids,
            @ApiParam(value = "用户ID", required = true, name = "userId", example = "1")
            @RequestParam Integer userId
    ) {
        return userCouponsService.batchDeleteUserCoupons(ids, userId);
    }

    @DeleteMapping("/physical/{id}")
    @Operation(summary = "物理删除用户优惠券（谨慎使用）")
    @ApiOperation(value = "物理删除用户优惠券（谨慎使用）", notes = "根据优惠券ID和用户ID物理删除用户持有的优惠券，此操作不可逆")
    public boolean physicallyDeleteUserCoupon(
            @ApiParam(value = "优惠券ID", required = true, name = "id", example = "1")
            @PathVariable Integer id,
            @ApiParam(value = "用户ID", required = true, name = "userId", example = "1")
            @RequestParam Integer userId
    ) {
        return userCouponsService.physicallyDeleteUserCoupon(id, userId);
    }
}